package data_structure;

public class leetcode_0169 {
    public int majorityElement(int[] nums) {
        int left=0;
        int right=nums.length-1;
        int num=0;
        int count=0;
        while(left<right){
            if(nums[left]==nums[right]){
                if(count==0){
                    num=nums[left];
                    count=2;
                }
                else{
                    if(num==nums[left]){
                        count+=2;
                    }
                    else{
                        count-=2;
                    }
                }
            }
            left++;
            right--;
        }
        if(count==0) return nums[left];
        return num;
    }
}
